package com.surrey.p2p.model;

public class CANZone {

	private double minX;
	private double maxX;
	private double minY;
	private double maxY;
	
	private CANZone(){};

	public CANZone(double minX, double maxX, double minY, double maxY) throws Exception {
		if(minX<0 || minX>1 ||
		   minY<0 || minY>1 ||
		   maxX<0 || maxX>1 ||
		   maxY<0 || maxY>1 ||
		   maxX<minX || maxY<minY		   
		   ){
		throw new Exception("Cannot initialise CAN Zone. Incorrect Values Provided.\n(" + minX+ " , " + maxX +" , " + minY + " , " + maxY );	
		}	
		this.minX = minX;
		this.maxX = maxX;
		this.minY = minY;
		this.maxY = maxY;
	}

	public double getMinX() {
		return minX;
	}

	public void setMinX(double minX) {
		this.minX = minX;
	}

	public double getMaxX() {
		return maxX;
	}

	public void setMaxX(double maxX) {
		this.maxX = maxX;
	}

	public double getMinY() {
		return minY;
	}

	public void setMinY(double minY) {
		this.minY = minY;
	}

	public double getMaxY() {
		return maxY;
	}

	public void setMaxY(double maxY) {
		this.maxY = maxY;
	}

	public CANZone splitOnX() {
		return null;
	}

	public CANZone splitOnY() {
		return null;
	}
	
	public Point getCentre(){
		try {
			return new Point((minX+maxX)/2,(minY+maxY)/2);
		} catch (Exception e) {
			System.err.println(e);
			return null;
		}
	}

	public boolean inZone(Point p) {
		return (p.getX() < maxX && p.getX() > minX && p.getY() < maxY && p.getY() > minY);
	}
}
